package com.leyikao.sms;

import java.util.HashMap;
import java.util.Set;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

public class SendSms {
	
	/**
	 * 发送短息
	 * @param phone
	 * 			   	手机号码
	 * @param smsDemoID
	 * 				 短息模板ID
	 * @param codeAndTime
	 * 				验证码及有效时间
	 * @return
	 */
	public static boolean sendSMS(String phone,String smsDemoID,String[] codeAndTime){
		boolean isSuccess = false;
		HashMap<String, Object> result = null;
		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init(SysConstant.SMS_SERVICEIP, SysConstant.SMS_SERVICEPORT);
		restAPI.setAccount(SysConstant.SMS_ACCOUNT_SID, SysConstant.SMS_AUTH_TOKEN);
		restAPI.setAppId(SysConstant.SMS_APPID);
		result = restAPI.sendTemplateSMS(phone,smsDemoID ,codeAndTime);
		System.out.println("SDKTestGetSubAccounts result=" + result);
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
			isSuccess = true;
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
		return isSuccess;
	}
	
	public static void main(String args[]){
		boolean is = SendSms.sendSMS("18600919913", "24400", new String[]{"0409","5"});
		System.out.println(is);
	}
}
